from typing import Optional, Generic, TypeVar
from pydantic import BaseModel, Field
from datetime import datetime

DataT = TypeVar('DataT')

class BaseSchema(BaseModel):
    """基础模型，包含公共字段"""
    id: Optional[int] = Field(None, description="唯一标识")
    created_at: Optional[datetime] = Field(None, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True

class PaginatedResponse(BaseModel, Generic[DataT]):
    """分页响应模型"""
    total: int = Field(..., description="总记录数")
    page: int = Field(..., description="当前页码")
    page_size: int = Field(..., description="每页记录数")
    items: list[DataT] = Field(..., description="数据列表")

class ResponseModel(BaseModel, Generic[DataT]):
    """统一响应模型"""
    code: int = Field(200, description="状态码")
    message: str = Field("success", description="提示信息")
    data: Optional[DataT] = Field(None, description="响应数据")